using ClientBasicData.Api.Application.Command;
using ClientBasicData.Api.DTOS;
using ClientBasicData.ErrorCode;
using ClientBasicData.Domain.Client;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace ClientBasicData.Api.Controllers
{
    /// <summary>
    /// 客户控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ClientController : ControllerBase
    {
        private readonly IMediator mediator;

        public ClientController(IMediator mediator)
        {
            this.mediator = mediator;
        }

        /// <summary>
        /// 获取客户下拉框数据
        /// </summary>
        /// <returns>客户列表</returns>
        [HttpGet]
        public async Task<ApiResult<List<ClientModel>>> GetClientDropdown()
        {
            GetClientDropdownCommand request = new GetClientDropdownCommand();
            return await mediator.Send(request);
        }

        /// <summary>
        /// 客户信息录入接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> CreateClient(CreateClientCommand request)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 获取客户信息接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiResult<List<ClientDto>>> Handle([FromQuery]GetClientCommand request)
        {
            return mediator.Send(request);
        }
    }
}
